package com.example.summary;

import com.example.summary.thread.Data;
import com.example.summary.thread.MyCallable;
import com.example.summary.thread.MyRunable;
import com.example.summary.thread.MyThread;
import com.sun.deploy.util.SystemUtils;
import com.sun.xml.internal.fastinfoset.util.QualifiedNameArray;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;

@SpringBootApplication
public class SummaryApplication {

    static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();

    public static void main(String[] args) {
        System.out.println("123".hashCode());
        System.out.println("234".hashCode());
        System.out.println("123".hashCode());

//        List<Data> a = new ArrayList<>();
//
//        a.add(new Data("a", "2019-09-06 14:39:00"));
//        a.add(new Data("b", "2019-09-06 14:40:00"));
//        a.add(new Data("b", "2019-09-06 14:45:00"));
//        a.add(new Data("b", "2019-09-06 14:50:00"));
//
//        System.out.println("begin" + LocalDateTime.now());
//        a.forEach(r -> {
//            executorService.schedule(() -> {
//                System.out.println(r.getA() + LocalDateTime.now());
//            }, parse(r.getBeginTime()).getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
//        });

    }

    public static Date parse(String date) {
        try {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static void testThread() {
        Thread thread1 = new Thread(() -> System.out.println("1"));
        thread1.run();

        synchronized (Object.class) {
            System.out.println(1);
        }
        Thread myThread = new MyThread();
        myThread.start();

        Thread thread = new Thread(new MyRunable());
        thread.start();

        MyCallable myCallable = new MyCallable();
        FutureTask future = new FutureTask(myCallable);
        Thread thread2 = new Thread(future);
        thread2.run();

        try {
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }


}

